package com.softa.common.sysconfig.config;

import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import com.alicp.jetcache.anno.config.EnableMethodCache;
import com.softa.common.sysconfig.cache.ShiroCacheManager;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Created by yangl on 2018/5/19.
 */
@Configuration
@Import({RedisAutoConfiguration.class})
@EnableMethodCache(basePackages = "com.softa")
@EnableCreateCacheAnnotation
public class CacheConfig {

    public CacheConfig(){

    }

//    @Bean
//    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
//        RedisTemplate redisTemplate = new RedisTemplate();
//        redisTemplate.setConnectionFactory(redisConnectionFactory);
//        StringRedisSerializer keySerializer = new StringRedisSerializer();
//        GenericFastJsonRedisSerializer valueSerializer = new GenericFastJsonRedisSerializer();
//        redisTemplate.setEnableTransactionSupport(Boolean.FALSE);
//        redisTemplate.setKeySerializer(keySerializer);
//        redisTemplate.setValueSerializer(valueSerializer);
//        redisTemplate.setHashKeySerializer(keySerializer);
//        redisTemplate.setHashValueSerializer(valueSerializer);
//        return redisTemplate;
//    }

    /**
     * shiro 缓存管理器
     * @return
     */
    @Bean
    public ShiroCacheManager shiroCacheManager(){
        return new ShiroCacheManager();
    }

    /**
     * spring-data-redis 目前只get，不put和del，原则上都用jetcache，除非key规则不一样
     * @param redisTemplate
     * @return
     */
//    @Bean
//    public SpringCacheManager cacheManager(RedisTemplate redisTemplate){
//        SpringCacheManager cacheManager  = new SpringCacheManager();
//        cacheManager.setRedisTemplate(redisTemplate);
//        return cacheManager;
//    }

}
